/**
 * 公告的JS方法
 */
XF.Notice = new function(){
	/**
	 * 周刊页面初始化
	 */
	this.init_week = function(){
		var areas = $("map[name=planetmap] area");
		$(areas).hover(function(){
			var articleId = $(this).attr("article");
			var coords = $(this).attr("coords").split(",");
			var left = coords[0];
			var top = coords[1];
			var width = parseInt(coords[2])-parseInt(coords[0]);
			var height = parseInt(coords[3])-parseInt(coords[1]);
			var url = $(this).attr("href");
			$("#weekly_cover").css({
				"width":width+"px",
				"height":height+"px",
				"top":top+"px",
				"left":left+"px",
				"display":"block"
			});
			$("#weekly_cover").bind("click",function(){
				XF.Notice.listWeekly_article(articleId);
			});
			$("#weekly_cover").bind("mouseleave",function(){
				$("#weekly_cover").css({
					"width":"100px",
					"height":"100px",
					"top":"0",
					"left":"0",
					"display":"none"
				});
			});
		},function(){
			
		});
	};
	
	
	this.listWeekly = function(){
		XF.lightSideBar('weekly_0'); 
		var url  = global.contextPath + "/notice/weekly"
		$.ajax({
		  url: url,
		  type: "post",
		  data: {},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  $("#noticeCenter").html(xhr);
		  }
		});
	};
	
	this.listWeekly_article = function(articleId){
		XF.lightSideBar('weekly_0'); 
		var url  = global.contextPath + "/notice/weekly/article"
		$.ajax({
		  url: url,
		  type: "post",
		  data: {articleId:articleId},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  $("#noticeCenter").html(xhr);
		  } 
		});
	};
	
	
	/**
	 * 列表页的初始化
	 */
	this.init = function(){
		$("select[name=group]").bind("change",function(){
			var v = $("select[name=group]").val();
			if("0"==v){
				$("#noticeAddForm tr[s=0]").show();
			}else if("1"==v){
				$("#noticeAddForm tr[s=0]").hide();
			}
		});
		_init_mobileSelect();
	};
	
	/**
	 * 默认的Notice列表方法
	 */
	this.listNotice = function(p,title,page){
		var data = {};
		if(typeof(p)!='undefined'){
			XF.lightSideBar('notice_'+p);
			data = {group:p};
		}else{
			XF.lightSideBar('listNotice');
		}
		$.ajax({
			type:'post',
			data:{title:title,group:p,pageNum:page},
			url:global.contextPath + "/notice/step",
			complete:function(xhr){
				xhr = xhr['responseText'];
				$('#noticeCenter').html(xhr);
			}
		});
	};
	
	
	/**
	 * 搜索方法：排序，关键字,管理的方法
	 */
	this.listNoticeSearch = function(orderByFieldReq,groupReq){
		var orderByField = null;
		var orderByMode = null;
		var title = null;
		var viceTitle = null;
		var isimportant = null;
		var istop = null;
		var group = null;
		
		title = $("input[name=title]").val();
		viceTitle = $("input[name=viceTitle]").val();
		isimportant = $("select[name=isimportant]").val();
		istop = $("select[name=istop]").val();
		group = $("input[name=group]").val();
		
		if(typeof(orderByFieldReq)!='undefined' && orderByFieldReq!=""){
			orderByField = orderByFieldReq;
			var td = $("th[orderByField="+orderByField+"]");
			orderByMode = td.find("span.px").attr("orderByMode");
		}
		if(typeof(groupReq)!='undefined' && groupReq!=""){
			XF.lightSideBar('notice_'+groupReq);
			group = groupReq;
		}

		 _notice_search(orderByField,orderByMode,title,viceTitle,isimportant,istop,group,"1");
	};
	
	/**
	 * 查看公告，仅查看
	 */
	this.readListNotice = function(groupReq,title,page){
		//tab的变化
		$("#noticeTab li").removeClass("focus");
		if(groupReq=='0'){
			$("#noticeTab li[group=0]").addClass("focus");
		}if(groupReq=='1'){
			$("#noticeTab li[group=1]").addClass("focus");
		}
		$("input[name=keywords]").val("");
		
		var group = null;
		if(typeof(groupReq)!='undefined'){
			group = groupReq;
		}
    	config.notice_search['args'] = [null,null,title,null,null,null,group];
    	if (typeof(page)!="undefined") {
        	SMT.xconfig.gvar.pageNum = page;
    	} else {
        	SMT.xconfig.gvar.pageNum = '1';
    	}
    	SMT.ajax(config.notice_search);
	};
	
	this.readListNoticeSearch = function(groupReq){
		var title = $("#keywords").val();
		var viceTitle = $("#viceTitle").val();
		 _notice_search(null,null,title,viceTitle,null,null,groupReq);
	};
	
	/**
	 * 管理
	 */
	this.managelistNotice = function(noticeGroup){
		XF.lightSideBar('listNotice_'+noticeGroup);
		_notice_search(null,null,null,null,null,null,noticeGroup,"1");
	};
	
	/**
	 * 添加公告
	 */
	this.addNotice = function(noticeGroup){
		XF.lightSideBar('addNotice_'+noticeGroup); 
		var url  = global.contextPath + "/notice/add"
		$.ajax({
		  url: url,
		  type: "post",
		  data: {group:noticeGroup},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  $("#noticeCenter").html(xhr);
		  }
		});
	};
	
	
	/**
	 * 添加成功的返回
	 */
	this.refreshAfterAddSuccess = function(group){
		//XF.Notice.managelistNotice();
		XF.Notice.listNotice(group,'',1);
	}
	
	/**
	 * 添加失败错误提示
	 */
	this.refreshAfterAddFaild = function(errorJson){
		if(typeof(errorJson)=="undefined")return;
		if(errorJson==null || errorJson=="")return;
		$("span[id*='errorTip']").hide();
		for(key in errorJson){
			var v = errorJson[key];
			var errorTip = $("#errorTip_"+key);
			errorTip.html(v);
			errorTip.show();
		}
	};
	
	/**
	 * 删除公告：单条
	 */
	this.deleteNotice = function(id){
		$.messager.confirm('提示',"确认删除这条公告？",function(r){
		    if (r){
				var url  = global.contextPath + "/notice/doDelete"
				$.ajax({
				  url: url,
				  type: "post",
				  data: {noticeId:id},
				  complete: function(xhr){
					  xhr = xhr['responseText'];
					  xhr = new Function("return " + xhr);
					  xhr = xhr();
					  xhr = xhr['status'];
					  if(xhr=="SUCCESS"){
						  $.messager.show({
							title:'提示',
							msg:'删除成功',
							timeout:3000,
							showType:'slide'
						  });
						  $(".userListWrap tr i[s="+id+"]").parent().parent().parent().remove();
					  }else if(xhr=="FAILD"){
						  $.messager.show({
							title:'提示',
							msg:'删除失败',
							timeout:5000,
							showType:'slide'
						  });
					  }
				   }
				});
		    }
		});
	};
	
	/**
	 * 编辑公告
	 */
	this.editNotice = function(id,p){
		var url  = global.contextPath + "/notice/edit";
		$.ajax({
		  url: url,
		  type: "post",
		  data: {noticeId:id,group:p},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  $("#noticeCenter").html(xhr);
		  }
		});
	};
	
	this.detail = function(id, title, page,groupReq){
		var url  = global.contextPath + "/notice/detail"
		$.ajax({
		  url: url,
		  type: "post",
		  data: {noticeId:id,title:title,pageNum:page,group:groupReq},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  $("#noticeCenter").html(xhr);
		  }
		});
	};
	
	this.noticeBack = function(group, page, title) {
		this.listNotice(group,title,page);

	}
	
    /**
     * 具体搜索方法实现
     */
    function _notice_search(orderByField,orderByMode,title,viceTitle,isimportant,istop,group,isManage){
    	if(typeof(isManage)!='undefined' && isManage=='1'){
        	config.notice_search_manage['args'] = [orderByField,orderByMode,title,viceTitle,isimportant,istop,group];
        	SMT.xconfig.gvar.pageNum = '1';
        	SMT.ajax(config.notice_search_manage);
    	}else{
        	config.notice_search['args'] = [orderByField,orderByMode,title,viceTitle,isimportant,istop,group];
        	SMT.xconfig.gvar.pageNum = '1';
        	SMT.ajax(config.notice_search);
    	}
    }

    
   function _init_mobileSelect(){
	   var isSendMobile = $("#isSendMobile");
	   var isSelectAllMobile = $("#isSelectAllMobile");
	   var mobilePanel_checkboxs = $(".mobilePanel_checkbox");
	   isSelectAllMobile.attr("checked","checked");
	   mobilePanel_checkboxs.attr("checked","checked");
	   isSendMobile.bind("click",function(){
		   if(isSendMobile.is(':checked')){
			   $(".mobileslist").show();
		   }else{
			   $(".mobileslist").hide();
		   }
		   _updateMobileValues();
	   });
	   
	   isSelectAllMobile.bind("click",function(){
		   if(isSelectAllMobile.is(':checked')){
			   mobilePanel_checkboxs.each(function(c){mobilePanel_checkboxs[c].checked=true;});
		   }else{
			   mobilePanel_checkboxs.removeAttr("checked","checked");
		   }
		   _updateMobileValues();
	   });
	   
	   mobilePanel_checkboxs.bind("click",function(e){
		   if(!$(e).is(':checked')){
			   if(isSelectAllMobile.is(':checked')){
				   isSelectAllMobile[0].checked=false;
			   }
		   }
		   _updateMobileValues();
	   });
	   _updateMobileValues();
   }
   
   /**
    * 更新隐藏字段值
    */
   function _updateMobileValues(){
	   var isSendMobile = $("#isSendMobile");
	   var mobilePanel_checkboxs = $(".mobilePanel_checkbox");
	   var v = "";
	   if(isSendMobile.is(':checked')){
		   mobilePanel_checkboxs.each(function(c){
			   if($(mobilePanel_checkboxs[c]).is(':checked')){
				   var text = $(mobilePanel_checkboxs[c]).parent().find(".mobilevalue").html();
				   var snum = text.replace(/[^0-9]/ig,""); 
				   v = v+snum+",";
			   }
		   });
	   }
	   $("input[name=mobiles]").val(v);
   }
    
}();

config.notice_search = {
	url: ""+global.contextPath+"/notice/list",
    argsOrder: ['orderByField','orderByMode','title','viceTitle','isimportant','istop','group'],
    needVar: true,
    replaceExp: '#replaceDiv',
    callBack: function() {
    }		
};

config.notice_search_manage = {
		url: ""+global.contextPath+"/notice/manageList",
	    argsOrder: ['orderByField','orderByMode','title','viceTitle','isimportant','istop','group'],
	    needVar: true,
	    replaceExp: '#noticeCenter',
	    callBack: function() {
	    }		
	};


//*******************************************分割线-以下为duty脚本***********************************************



/**
 * 值班表的JS方法
 */
XF.Duty = new function(){
	this.DefaultSiteId = null;
	this.DefaultDeptId = null;
	
	/**
	 * 默认的Duty方法
	 */
	this.listDuty = function(p){
		var data = {};
		XF.lightSideBar('duty_0');
		$.ajax({
			type:'post',
			data:data,
			url:global.contextPath + "/duty/step",
			complete:function(xhr){
				xhr = xhr['responseText'];
				$('#noticeCenter').html(xhr);
			}
		});
	};
	
	/**
	 * 跳转copy页面
	 */
	this.copyDutyFun = function(siteId,deptId){
		var data = {siteId:siteId,deptId:deptId};
		$.ajax({
			type:'post',
			data:data,
			url:global.contextPath + "/duty/stepCopy",
			complete:function(xhr){
				xhr = xhr['responseText'];
				$('#noticeCenter').html(xhr);
			}
		});
	};
	
	/**
	 * 查看值班表，仅查看
	 */
	this.readListDuty = function(deptId,siteId,dutyDate){
		var siteIdReq = null;
		if(typeof(siteId)!='undefined'){
			siteIdReq = siteId;
		}
		var deptIdReq = null;
		if(typeof(deptId)!='undefined'){
			deptIdReq = deptId;
		}
		_duty_search(deptId,siteId,dutyDate,null);
	};
	
	/**
	 * duty条件查询
	 */
	this.dutyListSearch = function(manage) {
		var dutyDate = $("#dutyTime").datebox('getValue');//String2017-7-17
		var siteId = $("#siteList").combobox('getValue');
		var deptId = $("#deptList").combobox('getValue');
		if(typeof(manage)!='undefined' && manage=='1'){
			_duty_search(deptId,siteId,dutyDate,'1');
		}else{
			_duty_search(deptId,siteId,dutyDate,null);
		}
	};
	
	/**
	 * 管理排班表
	 */
	this.manageDuty = function(siteIds,deptIds,dutyDates){
		XF.lightSideBar('duty_1');
		var siteId=null;
		var deptId=null;
		var dutyDate=null;
		if(typeof(siteIds)!='undefined'){
			siteId=siteIds;
		}if(typeof(deptIds)!='undefined'){
			deptId=deptIds;
		}
		if(typeof(dutyDates)!='undefined'){
			dutyDate=dutyDates;
		}
		_duty_search(deptId,siteId,dutyDate,'1');
	};
	
	/**
	 * 管理部门班次
	 */
	this.manageSchedule = function(){
		XF.lightSideBar('schedule_0');
		_duty_schedule_search(null,null);
	};
	
	/**
	 * schedule查询
	 */
	this.scheduleListSearch = function() {
		var siteId = $("#siteList").combobox('getValue');
		var deptId = $("#deptList").combobox('getValue');
		_duty_schedule_search(siteId,deptId);
	};
	
	
	/**
	 * 修改值班信息
	 */
	this.submitAddDuty = function(dutyJson,editSiteId,editDeptId,backDutyDate) {
		$.ajax({
			type:'post',
			url:global.contextPath + "/duty/doAddDuty",
			dataType: 'json',
			data:{dutyJson:dutyJson,editSiteId:editSiteId,editDeptId:editDeptId},
			success:function(result){
				if (result.status == 'SUCCESS') {
					$.messager.show({
						showType:'fade',
						msg:"操作成功",
						title:"提示",
						timeout:"3000"
					});
					XF.Duty.manageDuty(editSiteId,editDeptId,backDutyDate);
				} else {
					$.messager.show({
						showType:'fade',
						msg:"操作失败："+result.msg,
						title:"提示",
						timeout:"3000"
					});
				}
			}			
		});
	};
	
	/**
	 * 复制值班信息
	 */
	this.submitCopyDuty = function(dutyJson,editSiteId,editDeptId,backDutyDate) {	
		$.ajax({
			type:'post',
			url:global.contextPath + "/duty/doCopyDuty",
			dataType: 'json',
			data:{dutyJson:dutyJson,editSiteId:editSiteId,editDeptId:editDeptId},
			success:function(result){
				if (result.status == 'SUCCESS') {
					$.messager.show({
						showType:'fade',
						msg:"操作成功",
						title:"提示",
						timeout:"3000"
					});
					XF.Duty.manageDuty(editSiteId,editDeptId,backDutyDate);
				} else {
					$.messager.show({
						showType:'fade',
						msg:"操作失败："+result.msg,
						title:"提示",
						timeout:"3000"
					});
				}
			}			
		});
	};
	
	
	/**
	 * 修改值班表成功的返回
	 */
	this.refreshAfterAddDutySuccess = function(siteId,deptId,dutyDate){
		XF.Duty.manageDuty(siteId,deptId,dutyDate);
	};
	/**
	 * 删除值班信息
	 */
	this.deleteDuty = function(id,siteId,deptId,dutyDate) {
		$.messager.confirm('操作提示','确定删除这条记录吗',function(data){
			if(data){
				$.ajax({
					url:""+global.contextPath+"/duty/deleteDuty",
					type:"post",
					data:{dutyId:id},
					success:function(data){
						$.messager.show({
							title:'提示',
							msg:'删除成功',
							timeout:3000,
							showType:'slide'
						});
						XF.Duty.manageDuty(siteId,deptId,dutyDate);
					}
				});
			}
		});		
	};
	
	/**
	 * 删除班次信息
	 */
	this.deleteSchedule = function(id) {
		$.messager.confirm('操作提示','确定删除这个班次吗,与之关联的未生效值班信息将被删除！',function(data){
			if(data){
				$.ajax({
					url:""+global.contextPath+"/duty/deleteSchedule",
					type:"post",
					data:{scheduleId:id},
					success:function(data){
						$.messager.show({
							title:'提示',
							msg:'删除成功',
							timeout:3000,
							showType:'slide'
						});
						XF.Duty.manageSchedule();
					}
				});
			}
		});		
	};
	
	
	/**
	 * 跳转到添加Duty页面
	 */
	this.addDuty = function(siteId,deptId){
		XF.lightSideBar('duty_1');
		$.ajax({
			type:'post',
			data:{siteId:siteId,deptId:deptId},
			url:global.contextPath + "/duty/addDutys",
			complete:function(xhr){
				xhr = xhr['responseText'];
				$('#noticeCenter').html(xhr);
			}
		});
	};
	
	/**
	 * 添加失败错误提示
	 */
	this.refreshAfterAddFaild = function(errorJson){
		if(typeof(errorJson)=="undefined")return;
		if(errorJson==null || errorJson=="")return;
		$("span[id*='errorTip']").hide();
		for(key in errorJson){
			var v = errorJson[key];
			var errorTip = $("#errorTip_"+key);
			errorTip.html(v);
			errorTip.show();
		}
	};
	

	/**
	 * 编辑值班表
	 */
	this.editDuty = function(id,siteId,deptId,dutyDate){
		var url  = global.contextPath + "/duty/editDuty"
		$.ajax({
		  url: url,
		  type: "post",
		  data: {dutyId:id,siteId:siteId,deptId:deptId,dutyDate:dutyDate},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  $("#noticeCenter").html(xhr);
		  }
		});
	};
	
	/**
	 * 编辑部门班次
	 */
	this.editSchedule = function(scheduleId,siteId,deptId){
		var url  = global.contextPath + "/duty/editSchedule";
		$.ajax({
		  url: url,
		  type: "post",
		  data: {'scheduleId':scheduleId,siteId:siteId,deptId:deptId},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  $("#noticeCenter").html(xhr);
		  }
		});
	};
	
	
	/**
	 * 新增加部门班次
	 */
	this.addSchedule = function(siteId,deptId){
		var url  = global.contextPath + "/duty/addSchedule"
		$.ajax({
		  url: url,
		  type: "post",
		  data: {siteId:siteId,deptId:deptId},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  $("#noticeCenter").html(xhr);
		  }
		});
	};
	
	
    /**
     * 具体搜索值班表方法实现
     */
    function _duty_search(deptId,siteId,dutyDate,isManage){
    	if(typeof(isManage)!='undefined' && isManage=='1'){
        	config.duty_search_manage['args'] = [deptId,siteId,dutyDate];
        	SMT.xconfig.gvar.pageNum = '1';
        	SMT.ajax(config.duty_search_manage);
    	}else{
        	config.duty_search['args'] = [deptId,siteId,dutyDate];
        	SMT.xconfig.gvar.pageNum = '1';
        	SMT.ajax(config.duty_search);
    	}
    };
    
    /**
     * 搜索班次信息
     */
    function _duty_schedule_search(siteId,deptId){
        	config.duty_schedule_search['args'] = [siteId,deptId];
        	SMT.xconfig.gvar.pageNum = '1';
        	SMT.ajax(config.duty_schedule_search);
    };
    
    /**
     * 导出duty搜索值班表具体实现
     */
    function _duty_export(deptId,siteId,dutyDate){
        	config.duty_export['args'] = [deptId,siteId,dutyDate];
        	SMT.xconfig.gvar.pageNum = '1';
        	SMT.ajax(config.duty_export);
    };
    
    
    /**
     * 查询上/下周的duty信息
     */
    this.dutyWeekSearch = function(weekDate) {
		var dutyDate = weekDate;//String2017-7-17
		var siteId = $("#siteList").combobox('getValue');
		var deptId = $("#deptList").combobox('getValue');
		_duty_search(deptId,siteId,dutyDate,null);
	};
    
    /**
     * 查询需要导出的Duty数据
     */
    this.dutyExport = function(dutyTime) {
		var dutyDate = dutyTime;//String2017-7-17
		var siteId = $("#siteList").combobox('getValue');
		var deptId = $("#deptList").combobox('getValue');
		_duty_export(deptId,siteId,dutyDate);
	};
	

}();
   
/**
 * 值班表 查询配置
 */
config.duty_search = {
		url: ""+global.contextPath+"/duty/list",
	    argsOrder: ['deptId','siteId','dutyDate'],
	    needVar: true,
	    replaceExp: '#replaceDiv',
	    callBack: function() {
	    }		
	};

/**
 * 部门班次 查询配置
 */
config.duty_schedule_search = {
		url: ""+global.contextPath+"/duty/manageSchedules",
	    argsOrder: ['siteId','deptId'],
	    needVar: true,
	    replaceExp: '#noticeCenter',
	    callBack: function() {
	    }		
	};

/**
 * 值班表 导出配置
 */
config.duty_export = {
		url: ""+global.contextPath+"/duty/exportDuty",
	    argsOrder: ['deptId','siteId','dutyDate'],
	    needVar: true,
	    replaceExp: '#noticeCenter',
	    callBack: function() {
	    }		
	};


/**
 * 值班表管理配置
 */
config.duty_search_manage = {
		url: ""+global.contextPath+"/duty/manage",
	    argsOrder: ['deptId','siteId','dutyDate'],
	    needVar: true,
	    replaceExp: '#noticeCenter',
	    callBack: function() {
	    }		
	};



/**********破损件与不明件*********/
XF.Goods = new function() {
	/********破损与不明件*******/
    this.listDamaged = function(orderid, entersite,entertimeStart,entertimeEnd){
		XF.lightSideBar('listDamaged');
		_search_damaged(orderid,entersite,entertimeStart,entertimeEnd)
	};
	
	this.listDamagedSearch = function(){
		var orderid = $("input[name=orderid]").val();
		var entersite = $("#entersite").combobox('getValue');
		var entertimeStart = $("input[name=entertimeStart]").val();
		var entertimeEnd = $("input[name=entertimeEnd]").val();
		_search_damaged(orderid, entersite,entertimeStart,entertimeEnd);
    };
    function _search_damaged(orderid, entersite,entertimeStart,entertimeEnd){
    	config.damaged_search['args']=[orderid, entersite,entertimeStart,entertimeEnd];
    	SMT.xconfig.gvar.pageNum = '1';
    	SMT.ajax(config.damaged_search);   	
    };
    
    
    this.getImgURL = function(seqid) {
    	var url = global.contextPath+"/goods/getImgURL?seqid="+seqid;
    	$.getJSON(url, function(json){
    		  layer.photos({
    			shade: [0.8, '#393D49'],
    		    photos: json,
    		    anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
    		  });
    		}); 
    }
    
	this.listUnknown = function(entersite,recedateStart,recedateEnd,receclass,memo,goodsid,applysite,typesite){
		XF.lightSideBar('listUnknown');
		_search_unknown(entersite,recedateStart,recedateEnd,receclass,memo,goodsid,applysite,typesite)
	};
	
	this.listUnknownSearch = function(){
		var recedateStart = $("input[name=recedateStart]").val();
		var recedateEnd = $("input[name=recedateEnd]").val();
		var entersite = $("#entersite").combobox('getValue');
		var receclass = $("#receclass").combobox('getValue');
		var memo = $("#memo").val();
		var goodsid = $("#goodsid").val();
		var typesite = $("#typesite").combobox('getValue');
		var applysite = null;
		if(typesite =="1" ){
			applysite = $("#siteid").val();
			if(entersite == applysite){
                entersite =null;
			}
		}else if(typesite == "2"){
			entersite = $("#siteid").val();
		}
		_search_unknown(entersite,recedateStart,recedateEnd,receclass,memo,
				goodsid,applysite,typesite);
    };
    
    function _search_unknown(entersite, recedateStart,recedateEnd,receclass,memo,goodsid,
    		applysite,typesite){
    	config.unknown_search['args']=[entersite,recedateStart,recedateEnd,receclass,memo,
    		goodsid,applysite,typesite];
    	SMT.xconfig.gvar.pageNum = '1';
    	SMT.ajax(config.unknown_search);   	
    };
    /**
     * 查看申请状态0为当前站点1为其它站点可申请，2为其它站点不可申请
     */
    this.lookApply = function(seqid,identify) {
    	var siteid = $("#siteid").val();
    	var url = global.contextPath+"/goods/lookApply?seqid="+seqid;
    	$.getJSON(url, function(result){
    		if(result.sta == "ok"){
    			var applydata = result.data;
    			var applyTable = '<div class="oaTable"><table class="tableList"><tbody><tr><th style="width:140px;">认领站点</th><th style="width:100px;">认领人</th><th style="width:120px;">申请时间</th><th style="width:100px;">状态</th>';
    			if(identify == "0" || identify == "2"){
    				applyTable+= '<th style="width:100px;">操作</th>';
    			}
    				applyTable+= '</tr>';
    			for (var i = 0; i < applydata.length; i++) {
					var applysname = applydata[i].applysname;
					var applyusername = applydata[i].applyusername;
					var applytime = applydata[i].applytime;
					var status = applydata[i].status;
					var id = applydata[i].id;
					var seqid = applydata[i].seqid;
					applyTable+= '<tr style="height:40px;"><td>'+applysname+'</td><td>'+applyusername+'</td><td>'+applytime+'</td>';
					if(status ==0 && identify == "3"){
						applyTable+= '<td>...</td>';
					}else if(status == 1){
						applyTable+= '<td><font color="red">确认通过</font></td>';
					}else if(status ==0 && identify !="2"){
						applyTable+= '<td>申请中...</td>';
					}else if(identify=="2")
						applyTable+= '<td>...</td>';
					if(identify == 0){
						applyTable+= '<td><a class="a-btn-microsoft" style="color: White" href="javascript:XF.Goods.verifyUnknown('+id+',\''+seqid+'\')" >审核</a></td>';
					}else if(identify == 2 && status == 1){
						applyTable+= '<td><a class="a-btn-microsoft" style="color: White" href="javascript:XF.Goods.doVerify('+status+',\''+seqid+'\','+id+')" >取消审核</a></td>';
					}
					applyTable+= '</tr>';
					
				}
					applyTable+= '</tbody></table></div>';
    			layer.open({
    				type: 1,
    				title:'查看不明货物认领',
    				skin: 'layui-layer-lan', //加上边框
    				area: ['600px', '300px'],
    				content:applyTable
    			})
    			
    		}else{
    			layer.alert(result.msg, {
				    skin: 'layui-layer-lan',
				    closeBtn: 0
				  });
    		}
    	}); 
	}
    /**
     * 打开审核页面
     */
    this.verifyUnknown = function(id,seqid) {
    	var userid = $("#userid").val();
    	var username = $("#username").val();
    	var siteid = $("#siteid").val();
    	var sitename = $("#sitename").val();
    	var id = id;
    	var url = global.contextPath+"/goods/verifyUnknown?id="+id;
    	$.getJSON(url, function(result){
    		var json = result.data;
    		var apply = '<table class="formTable"><tr><td class="tdTitle">认领详情</td></tr><tr><td class="tdTitle">物品编号：</td><td style="text-align:left;"><input class="inputText" style="width: 200px;" type="text" value="'+json.goodsid+'" readonly></td></tr>';
		  	  apply+= '<tr><td class="tdTitle">认领人：</td><td style="text-align:left;"><input class="inputText" style="width: 200px;" type="text" value="'+json.applyusername+'" readonly></td></tr>';
		  	  apply+= '<tr><td class="tdTitle">认领网点：</td><td style="text-align:left;"><input class="inputText" style="width: 200px;" type="text" value="'+json.applysname+'" readonly></td></tr>';
		  	  apply+= '<tr><td class="tdTitle">描述：</td><td style="text-align:left;"><input class="inputText" style="width: 400px;" type="text" value="'+json.applymemo+'" readonly></td></tr>';
		  	  apply+= '<tr><td class="tdTitle">审核人：</td><td style="text-align:left;"><input class="inputText" style="width: 200px;" type="text"  value="'+username+'" readonly></td></tr>';
		  	  apply+= '<tr><td class="tdTitle">审核网点：</td><td style="text-align:left;"><input class="inputText" style="width: 200px;" type="text"  value="'+sitename+'" readonly></td></tr>';
		  	  apply+= '<tr><td class="tdTitle">描述：</td><td style="text-align:left;"><input class="inputText" style="width: 400px;" type="text" id="verifymemo" value="" ></td></tr></table>';
		  	layer.open({
				  type: 1,
				  title:'不明货物认领审核',
				  skin: 'layui-layer-lan', //加上边框
				  area: ['550px', '400px'], //宽高
				  content: apply,
				  btn: ['提交','取消'],
				  yes: function(index, layero){
					  var verifymemo = $('#verifymemo').val()+"";
					  $.ajax({
						url:global.contextPath+"/goods/doVerify",
						type:"post",
						data:{seqid:json.seqid,status:0,id:id,
							  verifysite:siteid,verifyuser:userid,
							  verifymemo:verifymemo},
						datatype:"json",
						success:function(result){
							if(result.sta=="ok"){
								layer.alert('认领申请已审核成功！', {
								  skin: 'layui-layer-lan', //样式类名
								  btn: ['关闭'],
								  yes: function(){
									layer.closeAll();
									var contnet = '<div><a href="javascript:XF.Goods.lookApply(\''+seqid+'\',\'2\')" class="easyui-linkbutton">认领查看</a></div>';
									$('#sta'+seqid).empty();
									$('#sta'+seqid).append(contnet);
									$(".easyui-linkbutton").linkbutton();
								  }
								});
							}else{
								layer.alert(result.msg, {
									  skin: 'layui-layer-lan', //样式类名
									  btn: ['关闭'],
									  yes: function(){
										layer.closeAll();
									  }
									});
							}
						},
					});
				  },
				  btn2: function(index, layero){
					  layer.close(index);
					 }
				});
    	});
	}
    /***
     * 审核与取消审核
     */
    this.doVerify = function(status,seqid,id) {
    	var status = status;
    	var seqid = seqid;
    	var id = id;
    	var siteid = $("#siteid").val();
    	layer.confirm('是否取消审核？', {
    		  btn: ['确定','取消'] //按钮
    		}, function(){
    			$.ajax({
						url:global.contextPath+"/goods/doVerify",
						type:"post",
						data:{seqid:seqid,id:id,status:status},
						datatype:"json",
						success:function(result){
							if(result.sta == "ok"){
								layer.alert(result.msg, {
									skin: 'layui-layer-lan', //样式类名
									btn: ['关闭'],
									yes: function(){
										layer.closeAll();
										var contnet = '<div><a href="javascript:XF.Goods.lookApply(\''+seqid+'\',\'0\')" class="easyui-linkbutton" style="color: red;">认领审核</a></div>';
										$('#sta'+seqid).empty();
										$('#sta'+seqid).append(contnet);
										$(".easyui-linkbutton").linkbutton();
									}
								});
							}else{
								layer.alert(result.msg, {
									skin: 'layui-layer-lan', //样式类名
									btn: ['关闭'],
									yes: function(){
										layer.closeAll();
									}
								});
							}
						}
    			});
    		}, function(){
    		  closeBtn: 0
    		});
	}
    /**
     * 申请不明件
     */
    this.applyUnknown = function(seqid,goodsid) {
    	var userid = $("#userid").val();
    	var username = $("#username").val();
    	var siteid = $("#siteid").val();
    	var sitename = $("#sitename").val();
    	var recedateStart = $("input[name=recedateStart]").val();
		var recedateEnd = $("input[name=recedateEnd]").val();
		var entersite = $("#entersite").combobox('getValue');
		var receclass = $("#receclass").combobox('getValue');
		var memo = $("#memo").val();
		var applysta = $("input:checkbox:checked").val();
    	var url = global.contextPath+"/goods/applyUnknown?seqid="+seqid+"&applysite="+siteid;
    	$.getJSON(url, function(result){
    		  var sta = result.sta;
    		  if(sta == "ok"){
    			  var apply = '<table class="formTable"><td class="tdTitle">物品编号：</td><td style="text-align:left;"><input class="inputText" style="width: 200px;" type="text" value="'+goodsid+'" readonly></td></tr>';
    			  	  apply+= '<td class="tdTitle">认领人：</td><td style="text-align:left;"><input class="inputText" style="width: 200px;" type="text" value="'+username+'" readonly></td></tr>';
    			  	  apply+= '<td class="tdTitle">认领网点：</td><td style="text-align:left;"><input class="inputText" style="width: 200px;" type="text" value="'+sitename+'" readonly></td></tr>';
    			  	  apply+= '<td class="tdTitle">描述：</td><td style="text-align:left;"><input class="inputText" style="width: 400px;" type="text" id="applymemo" value="" ></td></tr></table>';
    			  layer.open({
    				  type: 1,
    				  title:'不明货物认领申请',
    				  skin: 'layui-layer-lan', //加上边框
    				  area: ['550px', '260px'], //宽高
    				  content: apply,
    				  btn: ['提交','取消'],
    				  yes: function(index, layero){
    					  var applymemo = $('#applymemo').val()+"";
    					  if(applymemo == ""){
    						  layer.tips('描述不能为空！', '#applymemo');
    					  }else{
    						  $.ajax({
      							url:global.contextPath+"/goods/doAddApply",
      							type:"post",
      							data:{seqid:seqid,goodsid:goodsid,applysite:siteid,
      								applyuser:userid,applymemo:applymemo},
      							datatype:"json",
      							success:function(result){
      								if(result.sta=="ok"){
      									layer.alert('认领申请已登记！', {
        									  skin: 'layui-layer-lan', //样式类名
        									  btn: ['关闭'],
        									  yes: function(){
        										layer.closeAll();
        										var  html_btn = '<div><a href="javascript:XF.Goods.lookApply(\''+seqid+'\',\'1\')" class="easyui-linkbutton" >认领查看</a>';
        										html_btn += '<a href="javascript:XF.Goods.applyUnknown(\''+seqid+'\',\''+goodsid+'\',)" class="easyui-linkbutton" style="color: #1e71b1;">认领申请</a></div>';
        										$('#sta'+seqid).empty();
        										$('#sta'+seqid).append(html_btn);
        										$(".easyui-linkbutton").linkbutton();
        									  }
        									});
      								}else{
      									layer.alert(result.msg, {
          									  skin: 'layui-layer-lan', //样式类名
          									  btn: ['关闭'],
          									  yes: function(){
          										layer.closeAll();
          									  }
          									});
      								}
      							},
      						});
    					  }
    					  },
					  btn2: function(index, layero){
						  layer.close(index);
						 }
    				});
    		  }else{
    			  layer.alert(result.msg, {
    				    skin: 'layui-layer-lan'
    				    ,closeBtn: 0
    				  });
    		  }
    	}); 
	}
	
	
	
}();
/**
 * 查看破损件
 */
config.damaged_search = {
		url: ""+global.contextPath+"/goods/listDamaged",
	    argsOrder: ['orderid', 'entersite','entertimeStart','entertimeEnd'],
	    needVar: true,
	    replaceExp: '#noticeCenter',
	    callBack: function() {
	    }
};
/**
 * 查看不明件
 */
config.unknown_search = {
		url: ""+global.contextPath+"/goods/listUnknown",
	    argsOrder: ['entersite', 'recedateStart', 'recedateEnd','receclass','memo','goodsid','applysite','typesite'],
	    needVar: true,
	    replaceExp: '#noticeCenter',
	    callBack: function() {
	    }
};